create new dataframe from existing dataframe pandas

36

# Basic syntax:
new_dataframe = old_dataframe.filter(['Columns','you','want'], axis=1)
In [4]: import pandas as pd
In [5]: df = pd.DataFrame(columns=['A','B','C','D','E','F','G'])
In [6]: df
Out[6]:
Empty DataFrame
Columns: [A, B, C, D, E, F, G]
Index: []
new = old[['A', 'C', 'D']].copy()
new = old[['A', 'C', 'D']].copy()
new = old.filter(['A','B','D'], axis=1)

Comments

Submit
0 Comments